#include "stdafx.h"
#include "tinyxml.h"

const FStringA MAIN_INS_XML_URL = ("http://ctpandroid.applinzi.com/ins/main_ins.xml");

void createDeviceApp::GetMainInsText()
{
	FV_ACHAR buf;
	if (FHttpGet(MAIN_INS_XML_URL,buf)!=eHRR_OK)
	{
		return;
	}

	TiXmlDocument xmlDoc;
	if (xmlDoc.Parse(buf.begin(), 0, TIXML_ENCODING_UTF8))
	{
		TiXmlElement *XmlElem = xmlDoc.FirstChildElement("main_ins");
		if (!XmlElem)
			return;
		TiXmlElement *node = XmlElem->FirstChildElement("ins");
		while (node)
		{
			MainIns mainins;
			node->Attribute("id",&mainins.id);
			FUTF8ToUNICODE(mainins.szEN, node->Attribute("en"));
			FUTF8ToUNICODE(mainins.szCN, node->Attribute("cn"));
			mainIns.push_back(mainins);
			node = node->NextSiblingElement("ins");
		}
	}
}

int createDeviceApp::GetID(char *szIns)
{
	for (int i = 0; i < mainIns.size();i++)
	{
		if (strcmp(szIns, FStringA(mainIns[i].szEN).c_str()) == 0)
		{
			return mainIns[i].id;
		}
	}

	return 0;
}

FFString createDeviceApp::GetCNName(char *szIns)
{
	for (int i = 0; i < mainIns.size(); i++)
	{
		if (strcmp(szIns, FStringA(mainIns[i].szEN).c_str()) == 0)
		{
			return mainIns[i].szCN.c_str();
		}
	}

	return  FAssertFmtA(_FTA("%s"), szIns);
}